//package com.yc.biz.impl;
//import com.yc.entity.Mgoods;
//import com.yc.mapper.MgoodsMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.List;
//import java.util.Set;
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class HotProductRedisService {
//
//    private static final String HOT_PRODUCTS_KEY = "hot_products";
//
//    @Autowired
//    private RedisTemplate<String, String> redisTemplate;
//
//    public void addHotProductScore(int gid) {
//        // 每次访问商品时，增加其分数，这里简单增加1分
//        redisTemplate.opsForZSet().incrementScore(HOT_PRODUCTS_KEY, String.valueOf(gid), 1);
//    }
//
//    public Set<String> getHotProducts(int limit) {
//        // 获取最热门的商品，按分数从高到低排序，取前limit个
//        return redisTemplate.opsForZSet().reverseRange(HOT_PRODUCTS_KEY, 0, limit - 1);
//    }
//
//    @Autowired
//    private MgoodsMapper mgoodsMapper;
//
//
//
//    @PostConstruct
//    public void loadProductsToRedis() {
//        List<Mgoods> products = mgoodsMapper.findall();
//        for (Mgoods product : products) {
//            double randomScore = Math.random();
//            redisTemplate.opsForZSet().add(HOT_PRODUCTS_KEY, String.valueOf(product.getGid()), randomScore);
//        }
//    }
//}
